#include "ScnsSmctp.c.h"

#if defined(SCNS_SMCTP_ENABLE)&&SCNS_SMCTP_ENABLE==1

#include "ScnsMenu.h"
#include "ScnsMath.h"

const ScnsSmctpChanelConfig scnsSmctpChanelConfig[SCNS_SMCTP_CHANNEL_MAX]={
    [SCNS_SMCTP_CHANNEL_MENU]={.callback=scnsMenuReceiveInterrupt},

};

static lpuart_handle_t example_g_lpuartHandle;

static uint8 rxBuf[1];

static void example_uart_callback(LPUART_Type*base,lpuart_handle_t*handle,status_t status,void*userData)
{
    scnsSmctpReceive(rxBuf,1);
    handle->rxDataSize=sizeof(rxBuf);
    handle->rxData=rxBuf;
}

ScnsStatus scnsBspSmctpInit(void)
{
    uart_init(USART_1,460800,UART1_TX_B12,UART1_RX_B13);
    LPUART_TransferCreateHandle(LPUART1,&example_g_lpuartHandle,example_uart_callback,NULL);
    example_g_lpuartHandle.rxData=rxBuf;
    example_g_lpuartHandle.rxDataSize=1;
    LPUART_EnableInterrupts(LPUART1,kLPUART_RxDataRegFullInterruptEnable);
    NVIC_SetPriority(LPUART1_IRQn,1);
    return SCNS_STATUS_OK;
}

ScnsStatus scnsBspSmctpPostInit(void)
{
    return SCNS_STATUS_OK;
}

ScnsStatus scnsBspSmctpCanSend(void)
{
    return SCNS_STATUS_OK;
}

void scnsBspSmctpSend(const uint8*buf,uint32 *len)
{
    *len=scnsMin(*len,30);
    uart_putbuff(USART_1,buf,*len);
    scnsSmctpSendFinishCallback();
}
#endif